package com.rongc.client.freight.base.view.activity;


import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.WindowManager;
import android.webkit.JavascriptInterface;
import android.webkit.WebView;

import com.rongc.client.freight.R;
import com.rongc.client.freight.base.BaseActivity;

import butterknife.Bind;

public class WebActivity extends BaseActivity {
	@Bind(R.id.webview)
	WebView mWvContent;
	String type ;

	@Override
	public int getLayoutId() {
		return R.layout.activity_web;
	}

	@Override
	public void initParams() {
		type = getIntent().getStringExtra("type");
	}

	@Override
	public void initView() {
		if("pay".equals(type)){
			initToolbar(R.string.pay_rule_title);
		}else if("reg".equals(type)){
			initToolbar(R.string.reg_rule_title);
		}
	}

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE|WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
		mWvContent.getSettings().setJavaScriptEnabled(true);
		mWvContent.addJavascriptInterface(this, "javatojs");
		if("pay".equals(type)) {
			mWvContent.loadUrl("file:///android_asset/html/pay.html");
		}else if("reg".equals(type)){
			mWvContent.loadUrl("file:///android_asset/html/reg.html");
		}else{
			mWvContent.loadUrl("file:///android_asset/html/private.html");
		}

	}

	@JavascriptInterface
	public String getPrivate(){
		if("pay".equals(type)) {
			return getResources().getString(R.string.pay_rule);
		}else if("reg".equals(type)){
			return getResources().getString(R.string.reg_rule);
		}else {
			return "";
		}
	}

}
